﻿using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
namespace INTEX.DataBase.Tools
{
    public partial class INTEXDBC
    {
        public void MapICC_XDECK(ref DataRow dwLocal, DataRow dwData)
        {
            BlindMap(ref dwLocal, dwData);
        }
        public void SaveICC_XDECK(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            DataSet Result = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            Result = QueryICC_XDECK(dwData);
            if (Result.Tables.Count > 0)
            {
                tbLocal = Result.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }

            MapICC_XDECK(ref dwLocal, dwData);

            if (!flgExist)
            {
                InsertICC_XDECK(dwLocal, ITXDBVERSION);
            }
            UpdateICC_XDECK(dwLocal);

        }
        public void InsertICC_XDECK(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            string table = "VVPACK";  //VVPMANDANT	VVPLIEFSCH	VVPPACKNR
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            switch (ITXDBVERSION)
            {
                case "50.24":
                    or1.CommandText = "INSERT INTO ICC_XDECK(MANDANT, CONTROL,KRS, LFD, POS, TQTY, UPOS, MTYPE, ENDDATE, ART, VAR, COLOR, ASIZE, UM, CDES, ARTDES, QTYSTD, QTYPLAN, QTYACT, PRSTD, PREK, PRPLAN, VQTYSTDPRSTD, VQTYSTDPREK, VQTYSTDPRPLAN, VQTYPLANPRSTD, VQTYPLANPREK, VQTYPLANPRPLAN, VQTYACTPRSTD, VQTYACTPREK, VQTYACTPRPLAN, REQ, SELLER, SELLERNAME, REMARK)"
                        + " VALUES (:MANDANT, :CONTROL,:KRS, :LFD, :POS, 0, :UPOS, :MTYPE, 0,'ART', 'VAR', 'COLOR', 'ASIZE', 'MTR', 'CDES', 'ARTDES', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 'SELLER', 'SELLERNAME', 'REMARK')";
                    break;
                default:
                    break;
            }
            or1.Parameters.Add("MANDANT", OracleType.NVarChar).Value = dwData["MANDANT"].ToString();
            or1.Parameters.Add("CONTROL", OracleType.NVarChar).Value = dwData["CONTROL"].ToString();
            or1.Parameters.Add("KRS", OracleType.NVarChar).Value = dwData["KRS"].ToString();
            or1.Parameters.Add("LFD", OracleType.NVarChar).Value = dwData["LFD"].ToString();
            or1.Parameters.Add("POS", OracleType.NVarChar).Value = dwData["POS"].ToString();
            or1.Parameters.Add("UPOS", OracleType.NVarChar).Value = dwData["UPOS"].ToString();
            or1.Parameters.Add("MTYPE", OracleType.NVarChar).Value = dwData["MTYPE"].ToString();
            Connect2Proxy(or1);
        }
        public DataSet QueryICC_XDECK(DataRow dwData, int option = 1)
        {
            DataSet Return = new DataSet();
            DataTable tbLocal = null;
            DataSet Result = new DataSet();
            string table = "VKKOPF";

            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = "SELECT * FROM ICC_XDECK WHERE  "
            + "  MANDANT=:MANDANT AND KRS=:KRS AND LFD=:LFD AND POS=:POS AND UPOS=:UPOS";
                    or1.Parameters.Add("MANDANT", OracleType.NVarChar).Value = dwData["MANDANT"].ToString();
                    or1.Parameters.Add("KRS", OracleType.NVarChar).Value = dwData["KRS"].ToString();
                    or1.Parameters.Add("LFD", OracleType.NVarChar).Value = dwData["LFD"].ToString();
                    or1.Parameters.Add("POS", OracleType.NVarChar).Value = dwData["POS"].ToString();
                    or1.Parameters.Add("UPOS", OracleType.NVarChar).Value = dwData["UPOS"].ToString();
                    break;
                case 2:
                    or1.CommandText = "SELECT * FROM ICC_XDECK WHERE  "
            + "  MANDANT=:MANDANT AND KRS=:KRS AND LFD=:LFD ";
                    or1.Parameters.Add("MANDANT", OracleType.NVarChar).Value = dwData["MANDANT"].ToString();
                    or1.Parameters.Add("KRS", OracleType.NVarChar).Value = dwData["KRS"].ToString();
                    or1.Parameters.Add("LFD", OracleType.NVarChar).Value = dwData["LFD"].ToString();

                    break;
                default:
                    break;
            }

            Result = Connect2Proxy(or1);
            if (Result.Tables.Count > 0)
            {
                tbLocal = Result.Tables[0];
                tbLocal.TableName = "ICC_XDECK";
            }
            Return.Merge(Result);
            return Return;
        }
        public void UpdateICC_XDECK(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            OracleCommand or1;
            DataSet Result = new DataSet();
            or1 = OracleDB.CreateCommand();

            #region====Command====
            or1.CommandText = "UPDATE ICC_XDECK SET "
                + "CONTROL=:CONTROL,"
                 + "FART=:FART,"
                + "FVAR=:FVAR,"
                + "FCOLOR=:FCOLOR,"
                + "FASIZE=:FASIZE,"
                + "TQTY=:TQTY,"
                + "MTYPE=:MTYPE,"
                + "ENDDATE=:ENDDATE,"
                + "ART=:ART,"
                + "VAR=:VAR,"
                + "COLOR=:COLOR,"
                + "ASIZE=:ASIZE,"
                + "UM=:UM,"
                + "CDES=:CDES,"
                + "ARTDES=:ARTDES,"
                + "QTYSTD=:QTYSTD,"
                + "QTYPLAN=:QTYPLAN,"
                + "QTYACT=:QTYACT,"
                + "PRSTD=:PRSTD,"
                + "PREK=:PREK,"
                + "PRPLAN=:PRPLAN,"
                + "VQTYSTDPRSTD=:VQTYSTDPRSTD,"
                + "VQTYSTDPREK=:VQTYSTDPREK,"
                + "VQTYSTDPRPLAN=:VQTYSTDPRPLAN,"
                + "VQTYPLANPRSTD=:VQTYPLANPRSTD,"
                + "VQTYPLANPREK=:VQTYPLANPREK,"
                + "VQTYPLANPRPLAN=:VQTYPLANPRPLAN,"
                + "VQTYACTPRSTD=:VQTYACTPRSTD,"
                + "VQTYACTPREK=:VQTYACTPREK,"
                + "VQTYACTPRPLAN=:VQTYACTPRPLAN,"
                + "REQ=:REQ,"
                + "SELLER=:SELLER,"
                + "SELLERNAME=:SELLERNAME,"
                + "EKPAUF=:EKPAUF,"
                + "REMARK=:REMARK"
                + " WHERE  "
                + "  MANDANT=:MANDANT AND KRS=:KRS AND LFD=:LFD AND POS=:POS AND UPOS=:UPOS AND MTYPE=:MTYPE";
            #endregion

            #region====Parameters====

            or1.Parameters.Add("MANDANT", OracleType.NVarChar).Value = dwData["MANDANT"].ToString();
            or1.Parameters.Add("CONTROL", OracleType.NVarChar).Value = dwData["CONTROL"].ToString();
            or1.Parameters.Add("FART", OracleType.NVarChar).Value = dwData["FART"].ToString();
            or1.Parameters.Add("FVAR", OracleType.NVarChar).Value = dwData["FVAR"].ToString();
            or1.Parameters.Add("FCOLOR", OracleType.NVarChar).Value = dwData["FCOLOR"].ToString();
            or1.Parameters.Add("FASIZE", OracleType.NVarChar).Value = dwData["FASIZE"].ToString();
            or1.Parameters.Add("KRS", OracleType.NVarChar).Value = dwData["KRS"].ToString();
            or1.Parameters.Add("LFD", OracleType.NVarChar).Value = dwData["LFD"].ToString();
            or1.Parameters.Add("POS", OracleType.NVarChar).Value = dwData["POS"].ToString();
            or1.Parameters.Add("TQTY", OracleType.NVarChar).Value = dwData["TQTY"].ToString();
            or1.Parameters.Add("UPOS", OracleType.NVarChar).Value = dwData["UPOS"].ToString();
            or1.Parameters.Add("MTYPE", OracleType.NVarChar).Value = dwData["MTYPE"].ToString();
            or1.Parameters.Add("ENDDATE", OracleType.NVarChar).Value = dwData["ENDDATE"].ToString();
            or1.Parameters.Add("ART", OracleType.NVarChar).Value = dwData["ART"].ToString();
            or1.Parameters.Add("VAR", OracleType.NVarChar).Value = dwData["VAR"].ToString();
            or1.Parameters.Add("COLOR", OracleType.NVarChar).Value = dwData["COLOR"].ToString();
            or1.Parameters.Add("ASIZE", OracleType.NVarChar).Value = dwData["ASIZE"].ToString();
            or1.Parameters.Add("UM", OracleType.NVarChar).Value = dwData["UM"].ToString();
            or1.Parameters.Add("CDES", OracleType.NVarChar).Value = dwData["CDES"].ToString();
            or1.Parameters.Add("ARTDES", OracleType.NVarChar).Value = dwData["ARTDES"].ToString();
            or1.Parameters.Add("QTYSTD", OracleType.NVarChar).Value = dwData["QTYSTD"].ToString();
            or1.Parameters.Add("QTYPLAN", OracleType.NVarChar).Value = dwData["QTYPLAN"].ToString();
            or1.Parameters.Add("QTYACT", OracleType.NVarChar).Value = dwData["QTYACT"].ToString();
            or1.Parameters.Add("PRSTD", OracleType.NVarChar).Value = dwData["PRSTD"].ToString();
            or1.Parameters.Add("PREK", OracleType.NVarChar).Value = dwData["PREK"].ToString();
            or1.Parameters.Add("PRPLAN", OracleType.NVarChar).Value = dwData["PRPLAN"].ToString();
            or1.Parameters.Add("VQTYSTDPRSTD", OracleType.NVarChar).Value = dwData["VQTYSTDPRSTD"].ToString();
            or1.Parameters.Add("VQTYSTDPREK", OracleType.NVarChar).Value = dwData["VQTYSTDPREK"].ToString();
            or1.Parameters.Add("VQTYSTDPRPLAN", OracleType.NVarChar).Value = dwData["VQTYSTDPRPLAN"].ToString();
            or1.Parameters.Add("VQTYPLANPRSTD", OracleType.NVarChar).Value = dwData["VQTYPLANPRSTD"].ToString();
            or1.Parameters.Add("VQTYPLANPREK", OracleType.NVarChar).Value = dwData["VQTYPLANPREK"].ToString();
            or1.Parameters.Add("VQTYPLANPRPLAN", OracleType.NVarChar).Value = dwData["VQTYPLANPRPLAN"].ToString();
            or1.Parameters.Add("VQTYACTPRSTD", OracleType.NVarChar).Value = dwData["VQTYACTPRSTD"].ToString();
            or1.Parameters.Add("VQTYACTPREK", OracleType.NVarChar).Value = dwData["VQTYACTPREK"].ToString();
            or1.Parameters.Add("VQTYACTPRPLAN", OracleType.NVarChar).Value = dwData["VQTYACTPRPLAN"].ToString();
            or1.Parameters.Add("REQ", OracleType.NVarChar).Value = dwData["REQ"].ToString();
            or1.Parameters.Add("SELLER", OracleType.NVarChar).Value = dwData["SELLER"].ToString();
            or1.Parameters.Add("SELLERNAME", OracleType.NVarChar).Value = dwData["SELLERNAME"].ToString();
            or1.Parameters.Add("REMARK", OracleType.NVarChar).Value = dwData["REMARK"].ToString();
            or1.Parameters.Add("EKPAUF", OracleType.NVarChar).Value = dwData["EKPAUF"].ToString();
            #endregion

            Connect2Proxy(or1);
        }
    }
}
